package com.example.lj.uav.view;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;

import com.example.lj.uav.R;
import com.example.lj.uav.view.base.BaseActivity;

import static com.example.lj.uav.MyApplication.mPref;

public class Authority_Activity2 extends BaseActivity implements View.OnClickListener,CompoundButton.OnCheckedChangeListener {
    private CheckBox mIv1;
    private CheckBox mIv2;
    private CheckBox mIv3;
    private CheckBox mIv4;
    private CheckBox mCb1;
    private CheckBox mCb2;
    private CheckBox mCb3;
    private CheckBox mCb4;
    private Button mBtnNext;
    private LinearLayout mLl1;
    private LinearLayout mLl2;
    private LinearLayout mLl3;
    private LinearLayout mLl4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_authority_2);
        initView();
    }

    private void initView() {
        mIv1 = findViewById(R.id.iv_1);
        mIv2 = findViewById(R.id.iv_2);
        mIv3 = findViewById(R.id.iv_3);
        mIv4 = findViewById(R.id.iv_4);
        mCb1 = findViewById(R.id.cb_authority_1);
        mCb2 = findViewById(R.id.cb_authority_2);
        mCb3 = findViewById(R.id.cb_authority_3);
        mCb4 = findViewById(R.id.cb_authority_4);
        mBtnNext = findViewById(R.id.btn_authority2_next);
        mLl1 = findViewById(R.id.ll_authority2_1);
        mLl2 = findViewById(R.id.ll_authority2_2);
        mLl3 = findViewById(R.id.ll_authority2_3);
        mLl4 = findViewById(R.id.ll_authority2_4);
        mBtnNext.setEnabled(false);
        mIv1.setOnClickListener(this);
        mIv2.setOnClickListener(this);
        mIv3.setOnClickListener(this);
        mIv4.setOnClickListener(this);
        mBtnNext.setOnClickListener(this);
        mCb1.setOnCheckedChangeListener(this);
        mCb2.setOnCheckedChangeListener(this);
        mCb3.setOnCheckedChangeListener(this);
        mCb4.setOnCheckedChangeListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_1:
                if (mLl1.getVisibility()==View.VISIBLE){
                    mLl1.setVisibility(View.GONE);
                }else{
                    mLl1.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.iv_2:
                if (mLl2.getVisibility()==View.VISIBLE){
                    mLl2.setVisibility(View.GONE);
                }else{
                    mLl2.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.iv_3:
                if (mLl3.getVisibility()==View.VISIBLE){
                    mLl3.setVisibility(View.GONE);
                }else{
                    mLl3.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.iv_4:
                if (mLl4.getVisibility()==View.VISIBLE){
                    mLl4.setVisibility(View.GONE);
                }else{
                    mLl4.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.btn_authority2_next:
                mPref.edit().putBoolean("is_authority2_commit",true).apply();

                mPref.edit().putBoolean("mobile_gps", mCb1.isChecked()).apply();
                mPref.edit().putBoolean("dji_gps", mCb2.isChecked()).apply();
                mPref.edit().putBoolean("dji_hardware", mCb3.isChecked()).apply();
                mPref.edit().putBoolean("dji_fuzzy_position", mCb4.isChecked()).apply();
                toAct(MainActivity.class,true);
        }
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked){
            if (mCb1.isChecked()&&mCb2.isChecked()&&mCb3.isChecked()&&mCb4.isChecked()){
                mBtnNext.setEnabled(true);
            }
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return false;
    }
}
